<template>
    <div>
        <h1>会员信息修改</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>用户名</td>
                    <td><input type="text" v-model="data.MName"></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="data.MPass"></td>
                </tr>
                <tr>
                    <td>会员等级</td>
                    <td>
                        <select v-model="data.LeveId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.LeveId">{{a.LeveName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>会员头像</td>
                    <td>
                        <input type="file" @change="tu">
                        <img :src="'https://localhost:7174/'+data.MImg" style="width: 60px;height: 60px;">
                    </td>
                </tr>
                <tr>
                    <td>会员年龄</td>
                    <td><input type="text" v-model="data.MAge"></td>
                </tr>
                <tr>
                    <td>会员状态</td>
                    <td>
                        <input type="radio" name="MState" :value="'true'" v-model="data.MState">启用
                        <input type="radio" name="MState" :value="'false'" v-model="data.MState">禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="修改" @click="Add"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

onMounted(()=>{
    Xia()
    Fan()
})

//下拉框
const bang =ref([{
    "LeveId": 0,
    "LeveName": "",
    "LeveState": true,
    "QYId": 0
}])

const Xia = ()=>{
    axios.get('https://localhost:7174/api/Member/Xia').then(res=>{
        bang.value = res.data;
    })
}

const route = useRoute();
const router= useRouter()
//反填
const Fan=()=>{
    var c = route.query.MId
    axios.get('https://localhost:7174/api/Member/FanMember',{params:{MId:c}}).then(res=>{
        data.value = res.data;
    })
}


//图片上传
const tu = (e:any)=>{
    var f = e.target.files[0];
    var fd = new FormData();
    fd.append();

    if(e.size>2*1024*1024){
        alert('图片不能大于2MB')
        return;
    }

    axios.post('https://localhost:7174/api/Tup/Tu',fd).then(res=>{
        data.value.MImg = res.data
    })

}




//新增
const data = ref({
    "MId": 0,
  "MName": "",
  "MPass": "",
  "LeveId": 0,
  "MImg": "62bc0a5c-43be-4be2-8945-16cff4fdef653.jpg",
  "MAge": 0,
  "MState": true
})



const Add=()=>{
    if(data.value.MName==""){
        alert('用户名不能为空')
        return
    }
    if(data.value.MPass==""){
        alert('用户名不能为空')
        return
    }
    if(data.value.MAge==""){
        alert('年龄不能为空')
        return
    }
    axios.post('https://localhost:7174/api/Member/UpdMember',data.value).then(res=>{
        if(res.data>0){
            alert('修改成功');
            router.push({path:"/MemberShow"})
        }
        else{
            alert('修改失败')
        }
    })
}













</script>

<style scoped>

</style>